﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SnowDAL;

namespace Snow
{
    public partial class UserFace : PageBase
    {
        private UserDAL _dal = new UserDAL();

        public string FaceHtml = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnByUid_Click(object sender, EventArgs e)
        {
            DataBindFace();
        }

        private void DataBindFace()
        {
            FormatFaceHtml(_dal.QueryUserFace(ddlCount.SelectedValue));
        }

        private void FormatFaceHtml(DataTable dt)
        {
            foreach (DataRow row in dt.Rows)
            {
                FaceHtml += string.Format(
                    @" <li><a href='UUserDetail.aspx?uid={0}'>
                         <img src='{1}' width='100px' height='100px' onerror='image/dd.jpg' />
                         <br />{2}</a><input name='sel' type='checkbox' value='{0}'/> 
                      </li>", row["uid"].ToString(), Domain + row["face"].ToString(), row["name"]);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            FormatFaceHtml(_dal.QueryUserFaceByUid(txtUid.Text));
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            foreach (string uid in Request["sel"].Split(','))
                _dal.DeleteUserFace(uid);

            DataBindFace();
        }
    }
}

